var commentUrl = path + "ReplyServlet?method=addReply";

window.onload = function() {
	//点击评论按钮
	$("#a").click(function() {
		
		//获取评论内容
		var comment = $("#liuyan").val();
		//判断
		if(comment.length==0){
			alert("评论内容不能为空！");
			return ;
		}
		comment=window.encodeURIComponent(comment); //解析特殊字符，防止后台无法解析
		var parameter ="aid="+infoId+ "&userid="+userId+ "&message=" + comment;
		$.post(commentUrl, parameter, function(response) {
			if(response==0){//未登录
				window.location = path+"jsps/user/log.jsp";
			}else if(response==1){
				alert("评论成功！等待审核");
				window.location = path+"ArticleServlet1?method=findById&id="+infoId+"&readnum="+readnum;
			}else{
				alert("评论失败！");
			}
		});
	});
	




var publishUrl = getRootPath_web() + "/PublishServlet?method=forward"; //发表文章 的链接


	
	//点击转发按钮
	$("#forward").click(function() {
		//获取文章标题，正文
		var data = "title="+title+"&message="+message+"&userid="+userId+"&readnum="+readnum+"&uid="+uid;
//		alert(data);
		$.post(publishUrl, data, function(response) {
			if(response == 0) {//未登录
				window.location = path+"jsps/user/log.jsp";
			}else if(response == -1){//作者的id和登录者的id相同
				alert("转发失败！");
			}else{
				alert("转发成功！等待审核");
				window.location=getRootPath_web()+"/ArticleServlet1?method=findById&readnum=-1&id="+response;//返回到发表成功的帖子页面	
			}
		});
	
	});



function getRootPath_web() { //http://127.0.0.1:8020/codeforum
	
	//获取当前网址，如： http://localhost:8083/uimcardprj/share/meun.jsp
	var curWwwPath = window.document.location.href;
	//获取主机地址之后的目录，如： uimcardprj/share/meun.jsp
	var pathName = window.document.location.pathname;
	var pos = curWwwPath.indexOf(pathName);
	//获取主机地址，如： http://localhost:8083
	var localhostPaht = curWwwPath.substring(0, pos);
	//获取带"/"的项目名，如：/uimcardprj
	var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
	return(localhostPaht + projectName);
}

}
